package com.doit.day05

import java.io.{FileOutputStream, ObjectOutputStream}
import scala.beans.BeanProperty

object _06_面向对象之样例类 {
  def main(args: Array[String]): Unit = {
    val tiger: Tiger1 = new Tiger1("大脑斧", 2, 90)
    val tiger1: Tiger1 = new Tiger1("大脑斧", 2, 90)
    println(tiger)//com.doit.day05.Tiger1@45c8e616

    println(tiger.equals(tiger1))//false
    println(tiger.hashCode())
    println(tiger1.hashCode())

    val stream: ObjectOutputStream = new ObjectOutputStream(new FileOutputStream("d://a.txt"))
//    stream.writeObject(tiger)


    //case class 可以不用new 创建对象，说明自己创建了伴生类和伴生对象
    //还给我们重写了toString方法
    //还给我们重写了equals方法
    //还给我们重写了hashcode方法
    //还给我们实现了序列化接口
    val tiger2: Tiger = Tiger("大脑斧", 3, 90)
    val tiger3: Tiger = Tiger("大脑斧", 2, 90)
    println(tiger2)//Tiger(大脑斧,2,90.0)
    println(tiger2 == tiger3)//true
    println(tiger2.hashCode())
    println(tiger3.hashCode())
    stream.writeObject(tiger2)



  }
}


case class Tiger(@BeanProperty
                  name:String,
                 @BeanProperty
                 age:Int,
                 @BeanProperty
                 weight:Double)

class Tiger1(val name:String,
             val age:Int,
             val weight:Double)